<template>
    <div>
        <Title :title="title"></Title>
        <!-- 1.提供图标容器 -->
        <div ref="bottom4" style="height: 150px;margin-top: 30px;"></div>
    </div>
</template>
<script>
import { Area } from '@antv/g2plot';
import { get } from '@/utils/request';
import moment from 'moment';
export default {
    data() {
        return {
            title: '实时风向',
            params: {
                page: 1,
                pageSize: 100
            },
            tempData: []
        }
    },
    methods: {
        loadLine() {
            const area = new Area(this.$refs.bottom4, {
                data: this.tempData,
                xField: 'insert_time',
                yField: 'wind_direction',
                xAxis: {
                    range: [0, 1],
                    
                },
                
            });
            area.render();
        },
        async getTempData() {
            // 调用接口获取今日数据
            let res = await get('/dashboard/pageQueryTodayData', this.params);
            console.log(res, "获取响应");
            let temp = [];
            // 处理数据
            res.data.list.forEach((item, index, arr) => {
                arr[0].wind_direction = 60;
                // 格式化时间
                item.insert_time = moment(item.insert_time).format("HH:mm");
                // 每隔10条数据取一条，减少数据点数量
                if (index % 10 == 0) {
                    temp.push(arr[index])
                }
            });
            this.tempData = temp; // 保存处理后的数据
        },
    },
    async mounted() {
        await this.getTempData();
        this.loadLine();
    }
}
</script>
<style scoped></style>